package org.akomantoso.core.data.other;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.akomantoso.core.data.AnyOtherTypeElement;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;

/**
 * External tag when we use other namespace.
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 */
public final class ExternalTag implements AnyOtherTypeElement{

	private final String _prefix;
	private final String _name;

	private final Map<String, String> _attributes;

	public ExternalTag(String prefix, String name) {
		_prefix = prefix;
		_name = name;
		_attributes = new HashMap<String, String>(8);
	}

	public void add(String name, String value) {
		_attributes.put(name, value);
	}

	public String getName() {
		return _name;
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(new StringBuilder().append(_prefix).append(":").append(_name).toString()); 
		for (String key : _attributes.keySet()) {
			out.writeAttribute(key, _attributes.get(key));
		}
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
	}
	
	
	
}